package com.neusoft.edu.sys;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;





/**
* @name: BaseCtrl 
*
* @Copyright: (c) 2017 NEUSOFT. All rights reserved. 
*
* @description: 公共类
*
* @version: 1.0
* @date : 2017年6月29日 
* @author: Zhang.Yan
*
* @Modification  History:<br>
*  Date          Author         Version        Discription
*  
*/
@Component
public class AjaxResult
{
	@Value("${eureka.instance.instance-id}")
	private String instanceid;
	
	public Map<String, Object> ajaxResultSuccess()
    {
    	return ajaxResultSuccess(null,null);
    }
	public Map<String, Object> ajaxResultSuccess(String info)
    {
    	return ajaxResultSuccess( info, null);
    }
	
	public Map<String, Object> ajaxResultSuccess(Object data)
    {
    	return ajaxResultSuccess( "操作成功", data);
    }
    
    public Map<String, Object> ajaxResultFailure(String info)
    {
    	return ajaxResultFailure( info, "");
    }
    
    public Map<String, Object> ajaxResultFailure(String info,Exception e)
    {
    	return ajaxResultFailure( info+"发生系统错误:"+e.getLocalizedMessage()+",请联系管理人员！", "");
    }
    
    public Map<String, Object> ajaxResultFailure(Exception e)
    {
    	return ajaxResultFailure("发生系统错误:"+e.getLocalizedMessage()+",请联系管理人员！", "");
    }
    
    public Map<String, Object> ajaxResultSuccess(String info,Object data)
    {
    	return ajaxResultJson(1, info, data);
    }
    
    public Map<String, Object> ajaxResultFailure(String info,Object data)
    {
    	return ajaxResultJson(0, info, data);
    }
    
    public Map<String, Object> ajaxResultJson(Integer code,String info,Object data)
    {
    	Map<String, Object> result=new HashMap<String, Object>();
    	result.put("instanceid", instanceid);
    	result.put("code", code);
    	result.put("info", info==null?"操作成功":info);
    	result.put("data", data==null?"":data);
    	return result;
    }
}
